package com.honglv.controller.common;

import com.honglv.context.BaseContext;
import com.honglv.exception.BaseException;
import com.honglv.pojo.dto.PageByCityDTO;
import com.honglv.pojo.dto.LikeDTO;
import com.honglv.pojo.dto.PageDTO;
import com.honglv.pojo.dto.GetRounteDTO;
import com.honglv.pojo.dto.UpdateRounteDTO;
import com.honglv.pojo.result.Result;
import com.honglv.pojo.vo.GetRounteVO;
import com.honglv.pojo.vo.GetRountesByCityVO;

import com.honglv.pojo.vo.PageVO;
import com.honglv.pojo.vo.RounteShowVO;
import com.honglv.service.RounteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Slf4j
@Api("路线相关接口")
@RequestMapping("/rounte")
public class RounteController {
    @Autowired
    private RounteService rounteService;

    /**
     * 根据城市分页获取路线
     * @param
     * @return
     */
    @GetMapping("/getRountesByCity")
    @ApiOperation("根据城市分页获取路线")
    public Result<PageVO<GetRountesByCityVO>> getRountesByCity(PageByCityDTO pageByCityDTO){
        if (pageByCityDTO == null || pageByCityDTO.getPageSize() == null || pageByCityDTO.getPage() == null){
            throw new BaseException("参数为空");
        }
        PageVO<GetRountesByCityVO> pageVO = rounteService.getRountesByCity(pageByCityDTO);
        if (pageVO == null){
            return Result.success("暂无路线数据");
        }
        return Result.success(pageVO);
    }

    @GetMapping("/getRounte")
    @ApiOperation("获取路线详情页")
    public Result<GetRounteVO> getRounte(GetRounteDTO rounteDTO){
        if(rounteDTO == null || rounteDTO.getId() == null){
            throw new BaseException("参数为空");
        }
        GetRounteVO rounteVO = rounteService.getRounte(rounteDTO);
        if(rounteVO == null){
            return Result.success("无该路线数据");
        }
        return Result.success(rounteVO);
    }

    @GetMapping("/getRountesByAuthorId")
    @ApiOperation("个人中心获取路线")
    public Result<java.util.List<RounteShowVO>> getRountesByAuthorId(){
        Long userId = BaseContext.getCurrentId();
        if(userId == null){
            throw new BaseException("用户未登录");
        }
        List<RounteShowVO> list = (List<RounteShowVO>) rounteService.getRountesByAuthorId(userId);
        if(list == null){
            return Result.success("用户未写作路线");
        }
        return Result.success(list);
    }

    @GetMapping("/deleteRounte/{id}")
    @ApiOperation("删除路线")
    public Result deleteRounte(@PathVariable Long id){
        return rounteService.deleteRounte(id);
    }

    @GetMapping("/updateRounte")
    @ApiOperation("修改路线信息")
    public Result updateRounte(UpdateRounteDTO updateRounteDTO){
        return rounteService.updateRountel(updateRounteDTO);
    }

}
